package com.yhy.wxzn.wcs.device.rgv.bean;

import lombok.extern.slf4j.Slf4j;

import java.util.Objects;


@Slf4j
public class Lifter {

    private int x;
    private int y;

    public Lifter(Coord coord) {
        this.x = coord.getX();
        this.y = coord.getY();
    }

    public Lifter(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        return "Lifter{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Lifter lifter = (Lifter) o;
        return x == lifter.x &&
                y == lifter.y;
    }

    @Override
    public int hashCode() {

        return Objects.hash(x, y);
    }

    public static Lifter parseLifter(String str){
        Lifter lifter;
        try {
            String[] split = str.substring(1, str.length()-1).split(",");
            lifter = new Lifter(Integer.parseInt(split[0]),
                    Integer.parseInt(split[1]));

        }catch (Exception e){
            String msg = String.format("%s转为lifter对象失败原因为：%s", str, e.getMessage());
            log.error(msg);
            throw new RuntimeException(msg);
        }
        return lifter;
    }
    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

}
